import { Component, Graphics, Layers, Node, UITransform, _decorator } from 'cc';
import Sinusoid from '../Math/Sinusoid';
const { ccclass, property } = _decorator;

@ccclass('SinusoidManager')
export class SinusoidManager extends Component {


    @property({ type: Node })
    pen: Node = null;

    start() {
        this.pen.layer = Layers.Enum.UI_2D;
        let ctx = this.pen.getComponent(Graphics);
        ctx.lineWidth = 3;
    }


    draw(sinusoid: Sinusoid) {
        let ctx = this.pen.getComponent(Graphics);
        ctx.clear();

        let pW = this.pen.parent.getComponent(UITransform).width;

        let startX = -pW / 2;
        let endX = pW / 2;

        ctx.moveTo(startX, sinusoid.getY(startX));

        for (let i = startX + 1; i < endX; i++) {
            ctx.lineTo(i, sinusoid.getY(i))
        }
        ctx.stroke();
    }

    update(deltaTime: number) {

    }
}


